---
title: gluestack-ui Input Component | Installation, Usage, and API

description: The Input component is your go-to tool for gathering user input in a sleek and user-friendly text field. Whether you're designing a simple login form or a complex search feature, this component has got you covered.

pageTitle: Input

pageDescription: The Input component is your go-to tool for gathering user input in a sleek and user-friendly text field. Whether you're designing a simple login form or a complex search feature, this component has got you covered.

showHeader: true
---

import { Meta } from '@storybook/addon-docs';

<Meta title="with-gluestack-style/Components/Forms/Input" />

import {
  Input,
  InputField,
  InputIcon,
  InputSlot,
  Button,
  ButtonText,
  VStack,
  Text as GSText,
  Center,
  Box,
  FormControl,
  Heading,
  Icon,
  SearchIcon,
  EyeIcon,
  EyeOffIcon,
} from '../../core-components/themed';
import { transformedCode } from '../../utils';
import {
  AppProvider,
  CodePreview,
  Table,
  TableContainer,
  Text,
  InlineCode,
  CollapsibleCode,
  Tabs
} from '@gluestack/design-system';

import Wrapper from '../../core-components/themed/Wrapper';

This is an illustration of **Input** component.

<>
  <CodePreview
    showComponentRenderer={true}
    showArgsController={true}
    metaData={{
      code: `
        <Input {...props}>
          <InputField
              placeholder='Enter Text here'
          />
        </Input>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: {
        Wrapper,
        Input,
        InputField,
        InputIcon,
      },
      argsType: {
        variant: {
          control: 'select',
          options: ['rounded', 'outline', 'underlined'],
          default: 'outline',
        },
        size: {
          control: 'select',
          options: ['sm', 'md', 'lg', 'xl'],
          default: 'md',
        },
        isDisabled: {
          control: 'boolean',
          default: false,
        },
        isInvalid: {
          control: 'boolean',
          default: false,
        },
        isReadOnly: {
          control: 'boolean',
          default: false,
        },
      },
    }}
  />
</>

<br />

## Installation

<Tabs value="cli" type="section">
  <Tabs.TabList>
      <Tabs.Tab value="cli">
        <Tabs.TabTitle>CLI</Tabs.TabTitle>
      </Tabs.Tab>
     <Tabs.Tab value="manual">
        <Tabs.TabTitle>Manual</Tabs.TabTitle>
     </Tabs.Tab>
  </Tabs.TabList>
  <Tabs.TabPanels>
    <Tabs.TabPanel value="cli">
<>

### Run the following command:
  ```bash
  npx gluestack-ui add input
  ```
</>
    </Tabs.TabPanel>
    <Tabs.TabPanel value="manual"> 
<>

### Step 1: Install the following dependencies:
```bash
npm i @gluestack-ui/input
```

### Step 2: Copy and paste the following code into your project.
<CollapsibleCode>

```jsx 
%%-- File: core-components/themed/input/index.tsx --%% 
```
</CollapsibleCode>

### Step 3: Update the import paths to match your project setup.
</>
    </Tabs.TabPanel>
  </Tabs.TabPanels>
</Tabs>

## API Reference

To use this component in your project, include the following import statement in your file.

```jsx
import { Input } from '@/components/ui/input';
```

```jsx
export default () => (
  <Input>
    <InputField />
    <InputSlot>
      <InputIcon>{/* Some Icon Component */}</InputIcon>
    </InputSlot>
  </Input>
);
```

### Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

#### Input

It inherits all the properties of React Native's [View](https://reactnative.dev/docs/view) component.

<>
  <TableContainer>
    <Table>
      <Table.THead>
        <Table.TR>
          <Table.TH>
            <Table.TText>Prop</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Type</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Default</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Description</Table.TText>
          </Table.TH>
        </Table.TR>
      </Table.THead>
      <Table.TBody>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isInvalid</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`When true, the input displays an error state.`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isDisabled</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`When true, the input is disabled and cannot be edited.`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isHovered</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`When true, the input displays a hover state.`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isFocused</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`When true, the input displays a focus state.`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isRequired</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`If true, sets aria-required="true" on the input.`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>isReadOnly</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>bool</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>false</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`If true, the input value cannot be edited.`}</Table.TText>
          </Table.TD>
        </Table.TR>
      </Table.TBody>
    </Table>
  </TableContainer>
</>

**Descendants Styling Props**
Props to style child components.

<>
  <TableContainer>
    <Table>
      <Table.THead>
        <Table.TR>
          <Table.TH>
            <Table.TText>Sx Prop</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Description</Table.TText>
          </Table.TH>
        </Table.TR>
      </Table.THead>
      <Table.TBody>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>_input</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`Prop to style InputField Component`}</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>_icon</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`Prop to style InputIcon Component`}</Table.TText>
          </Table.TD>
        </Table.TR>
      </Table.TBody>
    </Table>
  </TableContainer>
</>

#### InputField

Contains all TextInput related layout style props and actions.
It inherits all the properties of React Native's [TextInput](https://reactnative.dev/docs/textInput#props) component.

<>
  <TableContainer>
    <Table>
      <Table.THead>
        <Table.TR>
          <Table.TH>
            <Table.TText>Prop</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Type</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Default</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Description</Table.TText>
          </Table.TH>
        </Table.TR>
      </Table.THead>
      <Table.TBody>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>type</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText> 'text' | 'password'</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>'text'</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`If true, the input component obscures the text entered so that sensitive text like passwords stay secure.`}</Table.TText>
          </Table.TD>
        </Table.TR>
      </Table.TBody>
    </Table>
  </TableContainer>
</>

#### InputSlot

It inherits all the properties of React Native's [Pressable](https://reactnative.dev/docs/pressable) component.

**Descendants Styling Props**
Props to style child components.

<>
  <TableContainer>
    <Table>
      <Table.THead>
        <Table.TR>
          <Table.TH>
            <Table.TText>Sx Prop</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Description</Table.TText>
          </Table.TH>
        </Table.TR>
      </Table.THead>
      <Table.TBody>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>_icon</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>{`Prop to style InputIcon Component`}</Table.TText>
          </Table.TD>
        </Table.TR>
      </Table.TBody>
    </Table>
  </TableContainer>
</>

#### InputIcon

Contains all Icon related layout style props and actions. It inherits all the properties of React Native's [View](https://reactnative.dev/docs/view) component.

### Features

- Keyboard support for actions.
- Support for hover, focus and active states.
- Option to add your styles or use the default styles.

### Accessibility

We have outlined the various features that ensure the Input component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards.Adheres to the [WAI-ARIA design pattern](https://www.w3.org/TR/wai-aria-1.2/#textbox).

#### Keyboard

- Setting the `aria-label` and `aria-hint` to help users understand the purpose and function of the Input

#### Screen Reader

- Compatible with screen readers such as VoiceOver and Talk-back.
- The `accessible` and `aria-label` props to provide descriptive information about the Input
- Setting `aria-traits` and `aria-hint` to provide contextual information about the various states of the Input, such as "double tap to edit".

#### Focus Management

- The `onFocus` and `onBlur` props to manage focus states and provide visual cues to users. This is especially important for users who rely on keyboard navigation.

#### States

- In error state, `aria-invalid` will be passed to indicate that the Input has an error, and providing support for an `aria-errormessage` to describe the error in more detail.
- In disabled state, `aria-hidden` will be passed to make input not focusable.
- In required state, `aria-required` will be passed to indicate that the Input is required.

### Props

Input component is created using TextInput component from react-native. It extends all the props supported by [React Native Text Input](https://reactnative.dev/docs/textinput#props), [utility props](/ui/docs/styling/utility-and-sx-props) and the props mentioned below.

#### Input

<>
  <TableContainer>
    <Table>
      <Table.THead>
        <Table.TR>
          <Table.TH>
            <Table.TText>Name</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Value</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Default</Table.TText>
          </Table.TH>
        </Table.TR>
      </Table.THead>
      <Table.TBody>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>size</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>xl | lg | md | sm</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>md</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>variant</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>underlined | outline | rounded</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>outline</Table.TText>
          </Table.TD>
        </Table.TR>
      </Table.TBody>
    </Table>
  </TableContainer>
</>

### Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

#### Input type password with FormControl

The Input component integrates with an icon and a button, providing users with a comprehensive login window inside a FormControl component.

<Wrapper>
  <CodePreview
    _rendererWrapper={{ py: '$8' }}
    showComponentRenderer={true}
    showArgsController={false}
    metaData={{
      code: `
        function App() {
          const [showPassword, setShowPassword] = React.useState(false);
          const handleState = () => {
            setShowPassword((showState) => {
              return !showState;
            });
          };
          return (
            <FormControl
              p='$4'
              borderWidth='$1'
              borderRadius='$lg'
              borderColor='$borderLight300'
              $dark-borderWidth='$1' $dark-borderRadius='$lg' $dark-borderColor='$borderDark800'
            >
              <VStack space='xl'>
                <Heading color='$text900' lineHeight='$md'>
                  Login
                </Heading>
                <VStack space='xs'>
                  <Text color='$text500' lineHeight='$xs'>
                    Email
                  </Text>
                  <Input>
                    <InputField
                      type="text"
                    />
                  </Input>
                </VStack>
                <VStack space='xs'>
                  <Text color='$text500' lineHeight='$xs'>
                    Password
                  </Text>
                  <Input textAlign='center'>
                    <InputField
                      type={showPassword ? 'text' : 'password'}
                    />
                    <InputSlot pr='$3' onPress={handleState}>
                      {/* EyeIcon, EyeOffIcon are both imported from 'lucide-react-native' */}
                      <InputIcon as={showPassword ? EyeIcon : EyeOffIcon}  color='$darkBlue500'/>
                    </InputSlot>
                  </Input>
                </VStack>
                <Button
                  ml='auto'
                  onPress={()=>{
                    setShowModal(false);
                  }}
                >
                  <ButtonText>
                    Save
                  </ButtonText>
                </Button>
              </VStack>
            </FormControl>
          );
        }
      `,
      transformCode: (code) => {
        return transformedCode(code, 'function', 'App');
      },
      scope: {
        Wrapper,
        Input,
        InputField,
        InputIcon,
        Button,
        ButtonText,
        VStack,
        Text: GSText,
        Heading,
        Icon,
        EyeIcon,
        EyeOffIcon,
        FormControl,
        InputSlot,
      },
      argsType: {},
    }}
  />
</Wrapper>

### Input with Icons

The Input with Icons is a variation of the Input component that displays icons next to input field. It's commonly used in apps for a more visual representation of options and easier navigation.

<Wrapper>
  <CodePreview
    showComponentRenderer={true}
    showArgsController={false}
    metaData={{
      code: `
        <Input>
          <InputSlot pl='$3'>
            <InputIcon as={SearchIcon}/>
          </InputSlot>
          <InputField
            placeholder="Search..."
          />
        </Input>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: {
        Wrapper,
        Input,
        InputField,
        InputIcon,
        SearchIcon,
        Icon,
        InputSlot,
      },
      argsType: {},
    }}
/>

</Wrapper>
